package com.guoqi.marrydate.calendar.schedule

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.guoqi.marrydate.R
import com.guoqi.marrydate.flag.FlagBean
import java.util.*

class ScheduleAdapter(private val mContext: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private var mSchedules: List<FlagBean>? = null

    init {
        initData()
    }

    private fun initData() {
        mSchedules = ArrayList()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ScheduleViewHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_calendar_item, parent, false))
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val bean = mSchedules!![position]
        val viewHolder = holder as ScheduleViewHolder
        when (bean.imgRes) {
            0 -> viewHolder.iv_icon.setImageResource(R.mipmap.ic_goal)
            1 -> viewHolder.iv_icon.setImageResource(R.mipmap.ic_eat)
            2 -> viewHolder.iv_icon.setImageResource(R.mipmap.ic_gift)
            3 -> viewHolder.iv_icon.setImageResource(R.mipmap.ic_cake)
            4 -> viewHolder.iv_icon.setImageResource(R.mipmap.ic_idea)
        }
        viewHolder.tv_title.text = bean.title
        viewHolder.tv_desc.text = bean.desc
    }

    override fun getItemCount(): Int {
        return mSchedules!!.size
    }

    inner class ScheduleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var iv_icon: ImageView = itemView.findViewById(R.id.iv_icon)
        var tv_title: TextView = itemView.findViewById(R.id.tv_title)
        var tv_desc: TextView = itemView.findViewById(R.id.tv_desc)
    }

    fun resetData(schedules: List<FlagBean>) {
        mSchedules = schedules
        notifyDataSetChanged()
    }




}
